<template>
	<view>
		<!--pages/Group-purchase/Group-purchase.wxml-->
		<view v-if="!empty">
			<image v-if="show_image" class="banner" mode="widthFix" :src="show_image"></image>
			<view class="title">拼团商品</view>
			<view class="listsbox" v-for="(item, index) in group_list" :key="index">
				<view class="lists">
					<view class="lists-left">
						<image mode="aspectFit" :src="item.image"></image>
					</view>
					<view class="lists-right">
						<view class="lists-right-a">{{ item.act_name }}</view>
						<view class="lists-right-b">已售{{ item.sell_number }}件</view>
						<view class="lists-right-c">
							<view class="lists-right-c-l">
								<view class="lists-right-c-l-a">￥{{ item.act_price }}</view>
								<view class="lists-right-c-l-c">原价：<text>￥{{ item.online_price }}</text></view>
							</view>
							<view @tap="todetail" class="lists-right-c-r" :data-id="item.id">立即开团</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>暂无拼团活动</view>
	</view>
</template>

<script>
	// pages/Group-purchase/Group-purchase.js
	var app = getApp().globalData;

	export default {
		data() {
			return {
				group_list: [],
				// 活动列表
				show_image: '',
				// 展示图
				empty: false // 判断

			};
		},

		components: {},
		props: {},
		onLoad(options) {
			// #ifdef MP-ALIPAY
			if (JSON.stringify(options) == '{}') {
				options = my.getLaunchOptionsSync().query;
			}
			// #endif
			if (options && (options.store_id)) {
				this.$store.store_id = options.store_id;
			}
		},
		// 加载数据
		async onShow() {
			await this.$onLaunched;
			this.getAllGroupList();
		},
		//  分享页面
		onShareAppMessage() {
			return {
				title: '拼团',
				path: '/pages/index/Group-purchase/Group-purchase?store_id=' + this.$store.store_id +
					'&share_uid=' + app.XcxData.userInfo.uid,
				success: function(res) { // 转发成功
				},
				fail: function(res) { // 转发失败
				}
			};
		},
		methods: {
			// 获取拼团列表
			getAllGroupList() {
				var that = this;
				uni.showLoading({
					title: '加载中',
					// #ifndef MP-ALIPAY
					mask: true,
					// #endif
				});
				getApp().globalData.sendRequest({
					url: '/Group/getAllGroupList',
					method: 'post',

					success(res) {
						uni.hideLoading();

						if (res.status == 1) {
							that.setData({
								group_list: res.all_group_list,
								show_image: res.show_image,
								empty: false
							});
						} else {
							that.setData({
								empty: true
							});
						}
					}

				});
			},

			// 立即开团
			todetail: function(e) {
				uni.navigateTo({
					url: '../Group-purchase-details/Group-purchase-details?id=' + e.currentTarget.dataset.id
				});
			}
		}
	};
</script>
<style>
	@import "./Group-purchase.css";
</style>
